<html>
<head><meta charset="utf-8"><title>GCX_PTR · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html">GCX_PTR</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205555191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555191">(Jul 31 2020 at 03:46)</a>:</h4>
<p>How does <a href="https://github.com/rust-lang/rust/blob/c058a8b8dc5dea0ed9b33e14da9e317e2749fcd7/src/librustc_middle/ty/query/job.rs#L13-L14">this code</a> work?</p>



<a name="205555203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555203">(Jul 31 2020 at 03:47)</a>:</h4>
<p>How does that <code>gcx_ptr</code> ref get returned as a pointer outside the closure without some kind of lifetime problems?</p>



<a name="205555207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555207">(Jul 31 2020 at 03:47)</a>:</h4>
<p>(I'm fiddling with this code, and when I changed it slightly I do get lifetime errors.)</p>



<a name="205555249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555249">(Jul 31 2020 at 03:48)</a>:</h4>
<p>My goal here is to simply eliminate <code>GCX_PTR</code>, because it's almost exactly duplicating the <code>TLV</code> that holds the <code>ImplicitCtxt</code></p>



<a name="205555254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555254">(Jul 31 2020 at 03:48)</a>:</h4>
<p>And it's only used by the deadlock handler for the parallel compiler</p>



<a name="205555322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555322">(Jul 31 2020 at 03:50)</a>:</h4>
<p>The <code>LocalKey</code> <a href="https://doc.rust-lang.org/std/thread/struct.LocalKey.html#method.with">docs</a> say "The <code>with</code> method yields a reference to the contained value which cannot be sent across threads or escape the given closure."</p>



<a name="205555328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555328">(Jul 31 2020 at 03:51)</a>:</h4>
<p>It sure seems like the reference is escaping the given closure</p>



<a name="205555482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205555482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205555482">(Jul 31 2020 at 03:55)</a>:</h4>
<p>Maybe because <code>GCX_PTR</code> is a thread-local with type <code>Lock&lt;usize&gt;</code>, and <code>Lock</code> is <code>Send</code> and <code>Sync</code>?</p>



<a name="205556983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205556983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205556983">(Jul 31 2020 at 04:35)</a>:</h4>
<p>Or maybe because this fn is <code>unsafe</code>?</p>



<a name="205563300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205563300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205563300">(Jul 31 2020 at 06:59)</a>:</h4>
<p>It casts the reference to a raw ptr and back.</p>



<a name="205563430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/GCX_PTR/near/205563430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/GCX_PTR.html#205563430">(Jul 31 2020 at 07:01)</a>:</h4>
<p>Within the closure it doesn't do the "and back" part</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>